package com.hospital.workstation.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.hospital.common.annotation.RepeatSubmit;
import com.hospital.common.annotation.Log;
import com.hospital.common.core.controller.BaseController;
import com.hospital.common.core.domain.PageQuery;
import com.hospital.common.core.domain.R;
import com.hospital.common.core.validate.AddGroup;
import com.hospital.common.core.validate.EditGroup;
import com.hospital.common.core.validate.QueryGroup;
import com.hospital.common.enums.BusinessType;
import com.hospital.common.utils.poi.ExcelUtil;
import com.hospital.workstation.domain.vo.TraditionalDiagnosisVo;
import com.hospital.workstation.domain.bo.TraditionalDiagnosisBo;
import com.hospital.workstation.service.ITraditionalDiagnosisService;
import com.hospital.common.core.page.TableDataInfo;

/**
 * 中医入院诊断
 *
 * @author whb
 * @date 2023-02-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workstation/traditionalDiagnosis")
public class TraditionalDiagnosisController extends BaseController {

    private final ITraditionalDiagnosisService iTraditionalDiagnosisService;

    /**
     * 查询中医入院诊断列表
     */
    @SaCheckPermission("workstation:traditionalDiagnosis:list")
    @GetMapping("/list")
    public TableDataInfo<TraditionalDiagnosisVo> list(TraditionalDiagnosisBo bo, PageQuery pageQuery) {
        return iTraditionalDiagnosisService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取中医入院诊断详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("workstation:traditionalDiagnosis:query")
    @GetMapping("/{id}")
    public R<TraditionalDiagnosisVo> getInfo(@NotNull(message = "主键不能为空")
                                             @PathVariable Long id) {
        return R.ok(iTraditionalDiagnosisService.queryById(id));
    }

    /**
     * 新增中医入院诊断
     */
    @SaCheckPermission("workstation:traditionalDiagnosis:add")
    @Log(title = "中医入院诊断", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TraditionalDiagnosisBo bo) {
        return toAjax(iTraditionalDiagnosisService.insertByBo(bo));
    }

    /**
     * 修改中医入院诊断
     */
    @SaCheckPermission("workstation:traditionalDiagnosis:edit")
    @Log(title = "中医入院诊断", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TraditionalDiagnosisBo bo) {
        return toAjax(iTraditionalDiagnosisService.updateByBo(bo));
    }

    /**
     * 删除中医入院诊断
     *
     * @param ids 主键串
     */
    @SaCheckPermission("workstation:traditionalDiagnosis:remove")
    @Log(title = "中医入院诊断", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iTraditionalDiagnosisService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
